package br.com.rafsoft.mapaentrega.server;

import java.util.List;
import java.util.logging.Logger;

import br.com.rafsoft.mapaentrega.server.entity.Message;
import br.com.rafsoft.mapaentrega.server.entity.Task;
import br.com.rafsoft.mapaentrega.server.entity.User;


public class MapaEntregaService {

private static final Logger log = Logger.getLogger(MapaEntregaService.class.getName());
	
	static DataStore db = new DataStore();

	public static Message createMessage() {
		log.info("Criada a tarefa.");
		return db.updateMessage(new Message());		
	}

	public static Message readMessage(Long id) {
		return db.findMessage(id);
	}

	public static Message updateMessage(Message message) {
		return db.updateMessage(message);
	}

	public static void deleteMessage(Message message) {
		db.deleteMessage(message.getId());
	}

	public static List<Message> queryMessages() {
		//db.updateMessage(new Message());
		return db.findAllMessage();
	}
	
	public static List<Message> queryMessagesUser(String user) {
		//db.updateMessage(new Message());
		return db.findAllMessage(user);
	}

	public static Task createTask() {
		log.info("Criada a tarefa.");
		return db.updateTask(new Task());		
	}

	public static Task readTask(Long id) {
		return db.findTask(id);
	}

	public static Task updateTask(Task task) {
		return db.updateTask(task);
	}

	public static void deleteTask(Task task) {
		db.deleteTask(task.getId());
	}

	public static List<Task> queryTasks() {
		return db.findAllTask();
	}
	
	public static List<Task> queryTasksUser(String user) {
		return db.findAllTask(user);
	}
	
	public static void updateTaskStatus(Long idTask, int status, String text) {
		Task task = db.findTask(idTask);
		task.setStatus(status);
		task.setStatusText(text);
		db.updateTask(task);
	}

	public static User createUser() {
		log.info("Criada a tarefa.");
		return db.updateUser(new User());		
	}

	public static User readUser(Long id) {
		return db.findUser(id);
	}

	public static User updateUser(User user) {
		return db.updateUser(user);
	}

	public static void deleteUser(User user) {
		db.deleteUser(user.getId());
	}

	public static List<User> queryUsers() {
		//db.updateUser(new User());
		return db.findAllUser();
	}
	
	public static User login(String user, String password) {
		return db.findUser(user, password);
	}

}
